# General information

This file joins all the final data (except for the calibration targets) in a single file.

## Input files

1. `1-Intermediate_Processed_Data/bilat_matrix_allyears.xlsx`
2. `1-Intermediate_Processed_Data/io_allyears.xlsx`
3. `1-Intermediate_Processed_Data/L_1999BLS.csv`
4. `1-Intermediate_Processed_Data/L_2000BLS.csv`
5. `1-Intermediate_Processed_Data/va_shares_allyears.xlsx`
6. `1-Intermediate_Processed_Data/exposures.xlsx`
7. `1-Intermediate_Processed_Data/L_2000CENSUS.csv`
8. `1-Intermediate_Processed_Data/mu_1999.xlsx`
9. `1-Intermediate_Processed_Data/mu_1999_no_migration.xlsx`

## Output files

1. `2-Final_Data/InputData.xlsx`

```{r setup, include=FALSE}
knitr::opts_knit$set(root.dir = normalizePath(".."))
remove(list = ls())  
```

```{r, warning=FALSE, message = FALSE}
wb <- createWorkbook()

bilat_matrix_allyears <- read_excel("1-Intermediate_Processed_Data/bilat_matrix_allyears.xlsx", sheet = 1)
addWorksheet(wb, sheetName = "BILATRAW")
writeData(wb, sheet = "BILATRAW", x = bilat_matrix_allyears)
saveWorkbook(wb, file = "2-Final_Data/InputData.xlsx", overwrite = TRUE)

io_allyears <- read_excel("1-Intermediate_Processed_Data/io_allyears.xlsx", sheet = 1)
addWorksheet(wb, sheetName = "IO")
writeData(wb, sheet = "IO", x = io_allyears)
saveWorkbook(wb, file = "2-Final_Data/InputData.xlsx", overwrite = TRUE)

va_shares_allyears <- read_excel("1-Intermediate_Processed_Data/va_shares_allyears.xlsx")
va_shares_allyears <- va_shares_allyears%>%filter(year == 2000)
addWorksheet(wb, sheetName = "VA")
writeData(wb, sheet = "VA", x = va_shares_allyears)
saveWorkbook(wb, file = "2-Final_Data/InputData.xlsx", overwrite = TRUE)

exposures <- read_excel("1-Intermediate_Processed_Data/exposures.xlsx")
exposures <- exposures[, c(1, 2)]
addWorksheet(wb, sheetName = "EXP")
writeData(wb, sheet = "EXP", x = exposures)
saveWorkbook(wb, file = "2-Final_Data/InputData.xlsx", overwrite = TRUE)

L_1999BLS <- read.csv("1-Intermediate_Processed_Data/L_1999BLS.csv")
addWorksheet(wb, sheetName = "L1999BLS")
writeData(wb, sheet = "L1999BLS", x = L_1999BLS)
saveWorkbook(wb, file = "2-Final_Data/InputData.xlsx", overwrite = TRUE)

L_2000BLS <- read.csv("1-Intermediate_Processed_Data/L_2000BLS.csv")
addWorksheet(wb, sheetName = "L2000BLS")
writeData(wb, sheet = "L2000BLS", x = L_2000BLS)
saveWorkbook(wb, file = "2-Final_Data/InputData.xlsx", overwrite = TRUE)

L_2000CENSUS <- read.csv("1-Intermediate_Processed_Data/L_2000CENSUS.csv")
addWorksheet(wb, sheetName = "L2000CENSUS")
writeData(wb, sheet = "L2000CENSUS", x = L_2000CENSUS)
saveWorkbook(wb, file = "2-Final_Data/InputData.xlsx", overwrite = TRUE)

mu_1999 <- read_excel("1-Intermediate_Processed_Data/mu_1999.xlsx")
addWorksheet(wb, sheetName = "MURAW")
writeData(wb, sheet = "MURAW", x = mu_1999)
saveWorkbook(wb, file = "2-Final_Data/InputData.xlsx", overwrite = TRUE)

mu_1999_no_migration <- read_excel("1-Intermediate_Processed_Data/mu_1999_no_migration.xlsx")
addWorksheet(wb, sheetName = "MURAWNM")
writeData(wb, sheet = "MURAWNM", x = mu_1999_no_migration)
saveWorkbook(wb, file = "2-Final_Data/InputData.xlsx", overwrite = TRUE)
```